﻿@inject IHttpService _httpService
@inject IPopupService PopupService
@inject IEventService _eventService

<MDCard>
    <DataTableCard TModel="StoreInfoViewModel" Headers="_headers" ApiUrl="@(_baseUrl)" ShowAddButton="false" Title="@($"{_name}列表")" @ref="dataTableCard">
        <ButtonContent>
            <CnGalWebSite.Shared.MasaComponent.Shared.Buttons.ExportButton OnQueryAsync="@(async ()=>await dataTableCard?.QueryAllAsync())" Name="商店信息" Class="me-4" />
        </ButtonContent>

        <ItemColContent>
            @if (context.Header.Value == "actions")
            {
                <MIcon Color="info"
                       Class="mr-2"
                       OnClick="()=>LookItem(context.Item)">@IconType.Look.ToIconString()</MIcon>
            }
            else
            {
                @context.Value
            }
        </ItemColContent>
    </DataTableCard>
</MDCard>




@code {
    private bool _editDialog;
    private long _editedItemId;
    private bool _detailDialog;

    private string _baseUrl = "api/tables/ListStoreInfo";
    private string _name = "商店信息";

    private List<DataTableHeader<StoreInfoViewModel>> _headers = new List<DataTableHeader<StoreInfoViewModel>>
    {
        new ()
          {
            Text= "链接",
            Align= DataTableHeaderAlign.Start,
            Value= nameof(StoreInfoViewModel.Link)
          },
          new (){ Text= "平台类型", Value= nameof(StoreInfoViewModel.PlatformType)},
          new (){ Text= "平台名称", Value= nameof(StoreInfoViewModel.PlatformName)},
          new (){ Text= "状态", Value= nameof(StoreInfoViewModel.State)},
          new (){ Text= "币种", Value= nameof(StoreInfoViewModel.CurrencyCode)},
          new (){ Text= "信息更新方式", Value= nameof(StoreInfoViewModel.UpdateType)},
          new (){ Text= "原价", Value= nameof(StoreInfoViewModel.OriginalPrice)},
          new (){ Text= "现价", Value= nameof(StoreInfoViewModel.PriceNow)},
          new (){ Text= "折扣", Value= nameof(StoreInfoViewModel.CutNow)},
          new (){ Text= "史低", Value= nameof(StoreInfoViewModel.PriceLowest)},
          new (){ Text= "最高折扣", Value= nameof(StoreInfoViewModel.CutLowest)},
          new (){ Text= "平均游玩时长 分钟", Value= nameof(StoreInfoViewModel.PlayTime)},
          new (){ Text= "评测数", Value= nameof(StoreInfoViewModel.EvaluationCount)},
          new (){ Text= "好评率", Value= nameof(StoreInfoViewModel.RecommendationRate)},
          new (){ Text= "估计拥有人数 上限", Value= nameof(StoreInfoViewModel.EstimationOwnersMax)},
          new (){ Text= "估计拥有人数 下限", Value= nameof(StoreInfoViewModel.EstimationOwnersMin)},
          new (){ Text= "更新时间", Value= nameof(StoreInfoViewModel.UpdateTime)},
          new (){ Text= "操作", Value= "actions",Sortable=false }
    };

    DataTableCard<StoreInfoViewModel> dataTableCard;

    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }

    public async Task LookItem(StoreInfoViewModel model)
    {
        await _eventService.OpenNewPage(GameReleaseViewModel.GetLink(model.PlatformType, model.Link));
    }
}
